import Vue from 'vue'
import VueRouter from 'vue-router'
const Login = () => import('views/login/Login.vue')
const Main = () => import('views/main/Main.vue')

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Login',
    component: Login
  },
  {
    path: '/main',
    name: 'Main',
    component: Main,
    children: []
  }
]

const _routes = []

const files = require.context('.', true, /router\.js$/)

const routesPath = files.keys()

for (const path of routesPath) {
  _routes.push(files(path).default)
}

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
_routes.forEach(route => router.addRoute('Main', route))

export default router
